/*
 * Copyright (C) 2013 rdrrlabs gmail com,
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.rdrrlabs.example.liblabs.utils;

/**
 * A generic pair of 2 objects.
 * <p/>
 * (Note: Amusingly there's a similar class in android.util.Pair)
 */
public class Pair<U, V> {

    private final U mFirst;
    private final V mSecond;

    public Pair(U first, V second) {
        mFirst = first;
        mSecond = second;
    }

    public U getFirst() {
        return mFirst;
    }

    public V getSecond() {
        return mSecond;
    }

    // Java Tip: due to type erasure, the static create() X and Y types have
    // really nothing to do with the U & V types of the non-static Pair class.
    // Using different letters for the generic types makes this more obvious.
    // More details at http://stackoverflow.com/questions/936377/static-method-in-a-generic-class
    public static <X, Y> Pair<X, Y> create(X first, Y second) {
        return new Pair<X, Y>(first, second);
    }

    @SuppressWarnings("unchecked")
    public static <X, Y> Pair<X, Y>[] newArray(int size) {
        return new Pair[size];
    }

    @Override
    public String toString() {
        return "Pair<" +
            (mFirst == null ? "(null)" : mFirst.toString())
            + ", " +
            (mSecond == null ? "(null)" : mSecond.toString())
            + ">";
    }
}
